package com.zto.wk.webflux.router;

import com.zto.wk.webflux.handler.CityHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * Created by wangkuan at 2018-08-02 14:00
 */
@Configuration
public class CityRouter {

    @Bean
    public RouterFunction<ServerResponse> routeCityHello(CityHandler cityHandler) {
        return RouterFunctions.route(
                RequestPredicates.GET("/city/hello")
                        .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                cityHandler::hello
        );
    }

    @Bean
    public RouterFunction<ServerResponse> routeCityBye(CityHandler cityHandler) {
        return RouterFunctions.route(
                RequestPredicates.GET("/city/bye")
                        .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                cityHandler::bye
        );
    }
}
